package com.op.teachingliteapp.fragment.resource;

import java.util.ArrayList;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.Toast;

import com.op.teachingliteapp.R;
import com.op.teachingliteapp.fragment.resourcedetails.ResourceDetailsFragment;
import com.op.teachingliteapp.util.ScreenSendUtils;

public class ResouceFragment extends Fragment {
private View root;
    
    @SuppressWarnings("unused")
	@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                              Bundle savedInstanceState) {

        View root = inflater.inflate(R.layout.fragment_resource, container,
                false);

        GridView gridview_material = (GridView) root
                .findViewById(R.id.gridView_material);
        ArrayList<ResourceCellDataProvider> list_material = new ArrayList<ResourceCellDataProvider>();
        if(list_material!=null){
        	list_material.clear();
        }else{ 
        	list_material.add(new ResourceCellDataProvider("课程PPT",R.drawable.ppt_normal));
        	list_material.add(new ResourceCellDataProvider("上机实验",R.drawable.computer_experiments_normal));
        	list_material.add(new ResourceCellDataProvider("视频资料",R.drawable.video_data_normal));
        	list_material.add(new ResourceCellDataProvider("课程案例",R.drawable.course_case_normal));
        	list_material.add(new ResourceCellDataProvider("上课计划",R.drawable.course_plan_normal));
        	list_material.add(new ResourceCellDataProvider("学生名单",R.drawable.student_list_normal));
        }
        ResourceGridAdapter  mAdapter = new ResourceGridAdapter(getActivity(), list_material);
        gridview_material.setAdapter(mAdapter);

        gridview_material.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                if (position == 0) {

                    /*
					 * 从这里点击进入ppt的选择
					 */
                    ResourceDetailsFragment detailsFragment =new ResourceDetailsFragment();
                    detailsFragment.setArguments(getArguments());
                    getFragmentManager()
                            .beginTransaction()
                            .addToBackStack(null)
                            .replace(R.id.fragment_replace_two,
                                    detailsFragment).commit();

                } else {
                    Toast.makeText(getActivity(), "可点击" + position,
                            Toast.LENGTH_SHORT).show();
                }
            }
        });

        this.root =root;
        return root;
    }


    @Override
    public void onResume() {
        super.onResume();
        ScreenSendUtils.sendWithDely(root);

    }
}
